package com.key.puzzlemodel.view

import android.app.Activity
import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.key.puzzlemodel.R


/**
 * @Description:
 * @Author: zhangguoliang
 * @CreateTime: 2020/7/3 10:49
 */
class ManageDialog(val activity: Activity, val title: String? = null) :
    Dialog(activity, R.style.manage_dialog) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val inflate = View.inflate(activity, R.layout.dialog_puzzle_manage, null)
        val txEmpty = inflate.findViewById<TextView>(R.id.tx_empty)
        title?.let {
            txEmpty.text = it
            txEmpty.visibility = View.VISIBLE
        }
        setContentView(inflate)
        setCancelable(false)
        val windowManager = activity.windowManager
        val display = windowManager.defaultDisplay
        val lp = window!!.attributes
        lp.width = activity.resources.getDimensionPixelOffset(R.dimen.dp_130)
        lp.height = activity.resources.getDimensionPixelOffset(R.dimen.dp_130)
        window!!.attributes = lp
    }

    override fun show() {
        try {
            if (!isShowing) {
                super.show()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun dismiss() {
        try {
            if (isShowing) {
                super.dismiss()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    fun setIsShow(it: Boolean) {
        if (it) {
            show()
        } else {
            dismiss()
        }
    }
}